var $ = function(Id){return document.getElementById(Id);}
function isIE(){if(document.all) return true;else return false;}
function isFF(){if(BV().n == 'Firefox') return true;else return false;}
function BV(){return {"n":navigator.appName,"v":navigator.appVersion};}
//determine if value is object return true and is not return false
function isObj(value){
    try{
        if(typeof(value)=='object') return true;
        else return false;
    }catch(e){
        return false;
    }
}
//checks the value of object is exists
function defined(value)
{
    try{
        if(typeof(value) == undefined) return false;
        else return true;
    }catch(e){
        return false;
    }
}
//get event element obj
function EObj(e)
{
    try {
        if (isIE()) return event.srcElement;
        else return arguments[0].target;
    }catch(e){
        return false;
    }
}
//get now active element obj
function ACT()
{
    return document.activeElement;
}
//get user key down code now
function getKeyDown(e)
{
    var em = IE ? event : arguments[0];
    return em.KeyCode;
}
//return array next or previous
function findNext(n,arr)
{
    if(n > 0) return arr[n-1];
    else return arr[n+1];    
}
//get now date time
function getDate()
{
    var myDate = new Date();
    var h = myDate.getHours();
    var i = myDate.getMinutes();
    var s = myDate.getSeconds();
    return h+":"+i+":"+s;
}
//Get the element Obj position and the element actual height
function getObjPos(obj)
{
    var y = obj.offsetTop;
    var x = obj.offsetLeft;
    var height = obj.scrollHeight;
    while(obj = obj.offsetParent) {    
        x += obj.offsetLeft;
        y += obj.offsetTop;
    }
    return [x,y,height];
}
//get the mouse cursor postion in browser
function getMousePos(e)
{
    if(isIE) e = event;else e = arguments[0];
    return {"x":e.clientX,"y":e.clientY};
}
//imitation window.eval
function ptEval(str)
{
    return Function('return '+str);
}
//execte command to mouse cursor select text
function ptExecCom()
{
    var args = arguments;
    var code = args[0];
    var mod = args[1] ? args[1] : false;
    var param = args[2] ? args[2] : null;
    if(isIE()) return document.selection.createRange().execCommand(code);
    else document.execCommand(code, mod , param);
}
//return one range object
function ptRange()
{
    if(isIE()) return document.selection.createRange();
    return document.createRange();
}
function Ajax()
{
    this.request = false;
    this.xmlHttp = null;
    this.timeOut = 10000;
    this.statusObj = null;
    this.statusCode = null;
    this.ctf = false;
    this.errorCode = null;
    this.rnd = function(){return ((new Date) *1);}
    this.exception = function(){}
    this.start = function(){}
    this.end = function(){}
    this.cancel = function(){}
    this.AjaxObj = function()
    {
        if(window.XMLHttpRequest) {
            this.request = new XMLHttpRequest();
            if(this.request.overrideMimeType) {
                this.request.overrideMimeType('text/html; charset=utf-8');
            }
        }else if(window.ActiveXObject) {
            var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
            for(var i=0; i<versions.length; i++) {
                try {
                    var reqObj = new ActiveXObject(versions[i]);
                    if(reqObj) {
                        this.request = reqObj;
                    }
                } catch(e) {
                    this.errorCode = 0;
                    this.exception();
                }
            }
        }else{
            this.errorCode = 0;
            this.exception();
        }
    }
    this.callServer = function(method, url, call, data, wait){
        this.xmlHttp = this.AjaxObj();
        var self = this;
        if (!xmlHttp) {
            this.errorCode = 0;
            return;
        }
        url += (url.indexOf("?") > -1 ? "&" : "?") + "rnd=" + this.rnd();
        this.xmlHttp.open(method, url, wait);
        this.start();
        if (method == "POST") this.xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        this.xmlHttp.send(data);
        function ReAbort(){
            self.ctf = true;
            this.xmlHttp.abort();
        }
        setTimeout(ReAbort, this.timeOut);
        this.xmlHttp.onreadystatechange = function(){
            if (self.ctf) {
                self.errorCode = 600;
                self.exception();
                return;
            }
            if (xmlHttp.readyState == 4) {
                this.statusCode = self.xmlHttp.status;
                try {
                    if (this.statusCode == 200) {
                        if (isset(call)) {
                            call(xmlHttp.responseText);
                        }
                    }
                    else {
                        self.errorCode = this.statusCode;
                        self.exception();
                        return;
                    }
                } catch (e) {
                    return self.exception();
                }
                this.end();
            }
        }
    }
}

